package com.longge;

import java.util.Arrays;

public class LargestPerimeter {

    public int largestPerimeter(int[] nums) {

        Arrays.sort(nums);

        int a = nums[nums.length - 1], b = nums[nums.length - 2], c = nums[nums.length - 3];

        for (int i = nums.length - 4; i >= 0; i--) {
            if (a >= b + c) {
                a = b;
                b = c;
                c = nums[i];
            } else {
                return a + b + c;
            }
        }
        return a >= b + c ? 0 : a + b + c;
    }

    public static void main(String[] args) {
        new LargestPerimeter().largestPerimeter(new int[]{3,6,2,3});
    }
}
